<template>
  <div class="app-container">
    <el-row :gutter="10" style="margin-bottom:20px;">
      <el-col :span="3">
        <el-input v-model="searchValue.account" placeholder="评委账号" clearable></el-input>
      </el-col>
      <el-col :span="3">
        <el-input v-model="searchValue.username" placeholder="评委名称" clearable></el-input>
      </el-col>
      <el-col :span="1.5">
        <el-button style=" background: #00BFD6; color: #FFFFFF; " @click="fetchData">
          搜索
          <i class="el-icon-search"></i>
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button style=" background: #00BFD6; color: #FFFFFF; " @click="reset">
          重置
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button style=" background: #00BFD6; color: #FFFFFF; " @click="addShow">增加 +</el-button>
      </el-col>
    </el-row>
    <el-table
      :data="tableData"
      border
      v-loading="listLoading"
      element-loading-text="Loading"
      fit
      highlight-current-row
      style="width:100%;"
    >
      <el-table-column type="index" label="序号" width="60"></el-table-column>
      <el-table-column prop="username" label="评委名称" min-width="120px"></el-table-column>
      <el-table-column prop="account" label="评委账号" min-width="120px"></el-table-column>
      <el-table-column prop="ip" label="最后登录IP" min-width="120px"></el-table-column>
      <el-table-column prop="date" label="最后登录时间" min-width="120px"></el-table-column>
      <el-table-column prop="telephone" label="联系方式" min-width="120px"></el-table-column>
      <el-table-column prop="realname" label="真实姓名" min-width="120px"></el-table-column>
      <el-table-column label="禁用" width="110">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.status"
            active-color="#00BFD6"
            inactive-color="#eaecf0"
            :active-value="1"
            :inactive-value="0"
            @change="changeStatus(scope.row.id,scope.row.status)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="110">
        <template slot-scope="scope">
          <el-button
            style="background-color:#00BFD6; color:#fff;border-radius: 6px;"
            size="small"
            @click="editShow(scope.row)"
          >编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin:40px 0">
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="searchValue.page"
        :limit.sync="searchValue.limit"
        @pagination="fetchData"
      />
    </div>
    <edit-dialog
      ref="myDetail"
      :dialogShow.sync="dialogShow"
      :data="editData"
      @onUpdate="fetchData"
        :close-on-click-modal="false"
    ></edit-dialog>
  </div>
</template>

<script>
import EditDialog from "../components/EditDialog";
import {
  accountList,
  accountStatus,
  accountDetail,
  accountAdd,
  accountEdit
} from "@/api/account";
export default {
  components: { EditDialog },
  data() {
    return {
      dialogShow: false, //新增面板 显示状态
      editData: {}, //编辑id
      searchValue: {
        account: null, //查询账号
        username: null, //评委名称
        page: 1,
        limit: 10,
       
      },
       total: 0,
      listLoading: false,
      tableData: []
    };
  },
  created() {
    this.fetchData();
  },

  methods: {
    // 账号禁用
    changeStatus(id, status) {
      let params = {};
      params.account_id = id;
      params.status = status;
      accountStatus(params).then(res => {
        this.fetchData();
        this.$message(res.msg);
      });
    },
    //  新增面板点击事件
    addShow() {
      this.editData = {};
      this.dialogShow = true;
    },
    editShow(item) {
      // console.log(item);
      this.dialogShow = true;
      this.editData = { ...item };
    },
    handleClick(row) {
      console.log(row);
    },
    handleSizeChange(val) {
      this.searchValue.limit = val;
      this.fetchData();
    },
    reset() {
      this.searchValue.account = null;
      this.searchValue.username = null;
      this.searchValue.page = 1;
      this.searchValue.limit = 10;
      this.total = 0;
      this.fetchData()
    },
    fetchData() {
      this.listLoading = true;
      let params = Object.assign({}, this.searchValue);
      accountList(params).then(res => {
        this.tableData = res.list;
        this.total = res.total;
        this.listLoading = false;
      });
    }
  }
};
</script>
<style scoped>
::v-deep .el-pagination.is-background .el-pager li:not(.disabled).active {
  background: #00bfd6 !important;
}
</style>